<!--
 * @Author: 刘翔
 * @Date: 2025-08-06 10:50:37
 * @LastEditTime: 2025-09-02 17:04:08
 * @LastEditors: your name
 * @Description:组合页面13(学科建设)
 * @FilePath: \建达文件\ts-demo\ts-demo\src\pptHome\pageList\pageType16.vue
-->
<template>
  <div class="page-type-16">
    <div class="page-type-16-left">
      <BarChart v-if="getChartProps1()" ref="radarChart" v-bind="getChartProps1()" />
      <CardBox>
        <template #right>
          <span class="card-box-right-item-1" v-html="desc"></span>
        </template>
      </CardBox>
    </div>
    <div class="page-type-16-right">
      <DataTable v-if="getTableProps1()" ref="table1" v-bind="getTableProps1()" />
    </div>
  </div>
</template>

<script>
import DataTable from '../components/DataTable.vue';
import BarChart from '../components/BarChart';
import CardBox from '../components/cardBox.vue';
export default {
  name: 'pageType16',
  components: {
    DataTable,
    BarChart,
    CardBox,
  },
  props: {
    tableData1: {
      type: Object,
      default: () => {},
    },
    chartList1: {
      type: Object,
      default: () => {},
    },
    desc: {
      type: String,
      default: '',
    },
  },
  methods: {
    getTableProps1() {
      return {
        tableData: this.tableData1.data,
        columns: this.tableData1.columns,
        tableParams: {
          headerHeight: 60,
        },
        pptOptions: {
          x: 6, // X轴位置
          y: 0.8, // Y轴位置
          h: 4.5, // 高度
          title: {
            // 标题配置
            x: 0.5,
            y: 0.5,
            fontSize: 24,
            color: '363636',
            bold: true,
          },
          table: {
            // 表格配置
            colW: this.tableData1.columns.map(item => this.pptWidthPercentFn(item.widthPercent)),
            // 表格内容配置
            content: {
              fontSize: 8,
              color: '000000',
              bold: true,
            },
            // 表格标题配置
            title: {
              fontSize: 8,
              color: 'ffffff',
            },
            // 表格边框样式
            borderStyle: {
              color: '000000',
            },
            // 表格垂直对齐方式(middle, top, bottom)
            valign: 'middle',
            // 表格水平对齐方式(left, center, right)
            align: 'center',
            // 自动分页
            autoPage: false,
            // 自动分页标题是否显示
            autoPageRepeatHeader: false,
            // 自动分页标题行数
            autoPageHeaderRows: 1,
          },
        },
      };
    },
    getChartProps1() {
      return {
        title: this.chartList1.title,
        categories: this.chartList1.data.map(item => item[this.chartList1.XShow]),
        values: this.chartList1.data.map(item => item[this.chartList1.keyList[0]]),
        color: this.chartList1.color,
        smooth: true,
        chartConfig: {
          height: 850,
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true,
          },
          tooltip: {
            textStyle: {
              fontSize: 18,
            },
            formatter: `{b}: {c}${this.chartList1.unitList[0]}`,
          },
          xAxis: {
            type: 'value',
            axisLabel: {
              fontSize: 18,
            },
          },
          yAxis: {
            type: 'category',
            axisLabel: {
              fontSize: 18,
            },
          },
          series: {
            barWidth: '40%',
            itemStyle: {
              normal: {
                color: function (params) {
                  return params.data >= 0 ? '#4874cb' : '#ee6666';
                },
              },
            },
            label: {
              position: 'right',
              show: true,
              fontSize: 18,
              formatter: `{c}${this.chartList1.unitList[0]}`,
            },
          },
        },
        pptConfig: {
          // 图表位置和大小
          position: {
            x: 0,
            y: 1,
            w: 6,
            h: 3.5,
          },
          // 标题配置
          title: {
            x: 1.8,
            y: 2.3,
            fontSize: 12,
            color: '363636',
            bold: true,
          },
          // 图表配置
          chart: {
            showLegend: false,
            legendPos: 'b',
            showTitle: false,
            //显示值
            showValue: true,
            //条形方向
            barDir: 'bar',
            // 分类轴字体大小
            catAxisLabelFontSize: 6,
            // 数据标签字体大小
            dataLabelFontSize: 7,
            //数值轴刻度步长(最大值的1.2倍)
            valAxisMajorUnit: Math.round(Math.max(...this.chartList1.data.map(item => Math.abs(item[this.chartList1.keyList[0]]))) * 1.2),
            // 数据标签位置
            dataLabelPosition: 'outEnd',
            // 分类轴标签位置
            catAxisLabelPos: 'low',
            // 数据标签格式化代码
            dataLabelFormatCode: `[黑色]#,##0.00"${this.chartList1.unitList[0]}"`,
          },
        },
      };
    },
    // 计算ppt宽度百分比(3.5是ppt表格目前总宽度)
    pptWidthPercentFn(pptWidthPercent) {
      return (pptWidthPercent / 100) * 3.5;
    },

    exportToPPT(pptx, slide) {
      this.$refs.radarChart.exportToPPT(pptx, slide);
      this.$refs.table1.exportToPPT(pptx, slide);
      //卡片
      slide.addText(
        [
          {
            text: `${this.desc}`,
            options: {
              fontSize: 12,
              color: '363636',
            },
          },
        ],
        {
          shape: pptx.shapes.ROUNDED_RECTANGLE,
          x: 0.5,
          y: 4.5,
          w: '50%',
          h: 0.8,
          rectRadius: 0.2,
          //边框
          line: { color: '151515', width: 0.5 },
          fill: { color: 'fff2ca' },
        }
      );
    },
  },
};
</script>

<style lang="less" scoped>
.page-type-16 {
  display: flex;
  width: 100%;
  height: 100%;
  .page-type-16-left {
    display: flex;
    flex-direction: column;
    width: 50%;
    height: 100%;
  }
  .page-type-16-right {
    width: 50%;
    height: 100%;
  }
  .card-box-container {
    margin: 10px 0;
    width: 95%;
    justify-content: left;
  }
}
</style>
